function hasKey(obj,key){
    for(let k in obj){
        if(k==key){
            return true
        }
    }
    return false
}
export function match_convert(match){
    let my_matcher = {}
    let headers = match[0]["headers"]
    let user_agent = headers["user_agent"]
    let user_agent_value= user_agent["value"]

    let cookie = headers['cookie']
    let cookie_type = cookie['type'] 
    let cookie_value = cookie['value']

    let custom_header   = headers['custom_header']
    let custom_header_type= custom_header["type"] 
    let custom_header_key = custom_header["key"]
    let custom_header_value = custom_header["value"]

    let uri = match[0]["uri"]
    let uri_type = uri['type']
    let uri_value = uri['value']

    if (user_agent_value){
        if (hasKey(my_matcher,'headers')==false){
            my_matcher['headers']={
                "User-Agent":{
                    "regex": user_agent_value
                }
            }
        }else{
            my_matcher['headers']['User-Agent']={
                'regex':user_agent_value
            }
        }
    }

    if(cookie_value){
        if (hasKey(my_matcher,'headers')==false){
            my_matcher['headers']= {
                "cookie": {
                    [cookie_type]: cookie_value
                }
            }
        }else{
            my_matcher['headers']['cookie']={
                [cookie_type]: cookie_value
            }
        }
    }
    if(custom_header_value){
        if (hasKey(my_matcher,'headers')==false){
            my_matcher['headers'] = {
                custom_header_key:{
                    [custom_header_type]: custom_header_value
                }
            }
        }else{
            my_matcher['headers'][custom_header_key]={
                [custom_header_type]: custom_header_value
            }
        }
    }
    if(uri_value){
        if (hasKey(my_matcher,'uri')==false){
            my_matcher['uri']={
                [uri_type]:uri_value
            }
        }else{
            my_matcher['uri'][uri_type]=uri_value
        }
    }
    return my_matcher
}